package com.yunhai.web.controller.other;

import java.util.List;
import java.util.Arrays;

import com.yunhai.system.service.TimeLineService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunhai.common.annotation.Log;
import com.yunhai.common.core.controller.BaseController;
import com.yunhai.common.core.domain.AjaxResult;
import com.yunhai.common.enums.BusinessType;
import com.yunhai.system.domain.TimeLine;
import com.yunhai.common.utils.poi.ExcelUtil;
import com.yunhai.common.core.page.TableDataInfo;

/**
 * 公司介绍--发展历程Controller
 *
 * @author jxj
 * @date 2021-01-16
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/other/timeLine")
public class TimeLineController extends BaseController {

    private final TimeLineService timeLineService;

    /**
     * 查询公司介绍--发展历程列表
     */
    @PreAuthorize("@ss.hasPermi('other:timeLine:list')")
    @GetMapping("/list")
    public TableDataInfo list(TimeLine timeLine) {
        startPage();
        List<TimeLine> list = timeLineService.queryList(timeLine);
        return getDataTable(list);
    }

    /**
     * 导出公司介绍--发展历程列表
     */
    @PreAuthorize("@ss.hasPermi('other:timeLine:export')")
    @Log(title = "公司介绍--发展历程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TimeLine timeLine) {
        List<TimeLine> list = timeLineService.queryList(timeLine);
        ExcelUtil<TimeLine> util = new ExcelUtil<TimeLine>(TimeLine.class);
        return util.exportExcel(list, "timeLine");
    }

    /**
     * 获取公司介绍--发展历程详细信息
     */
    @PreAuthorize("@ss.hasPermi('other:timeLine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(timeLineService.getById(id));
    }

    /**
     * 新增公司介绍--发展历程
     */
    @PreAuthorize("@ss.hasPermi('other:timeLine:add')")
    @Log(title = "公司介绍--发展历程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TimeLine timeLine) {
        return toAjax(timeLineService.save(timeLine) ? 1 : 0);
    }

    /**
     * 修改公司介绍--发展历程
     */
    @PreAuthorize("@ss.hasPermi('other:timeLine:edit')")
    @Log(title = "公司介绍--发展历程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TimeLine timeLine) {
        return toAjax(timeLineService.updateById(timeLine) ? 1 : 0);
    }

    /**
     * 删除公司介绍--发展历程
     */
    @PreAuthorize("@ss.hasPermi('other:timeLine:remove')")
    @Log(title = "公司介绍--发展历程", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(timeLineService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
